import { _decorator, Component, Node, Sprite, SpriteAtlas, tween, Tween, Vec3 } from 'cc';
import { $planet_AudioManager_poof$ } from '../manager/audio-manager';
import $planet_Config_poof$ from '../manager/config.dynamic';
const { ccclass, property } = _decorator;

@ccclass('$planet_Good_poof$')
export class $planet_Good_poof$ extends Component {
	@property(SpriteAtlas)
	private $planet_atlas_poof$: SpriteAtlas = null;

	private $planet_sprite_poof$: Sprite;

	private $planet_scale_poof$: Vec3;

	protected onLoad(): void {
		this.$planet_sprite_poof$ = this.node.getComponent(Sprite);
		this.$planet_scale_poof$ = Vec3.ONE.clone().multiplyScalar(1.5);
		this.node.active = false;
	}

	$planet_show_poof$(hit: number){
		let np = new abd.$planet_NudityPromise_poof$<Node>();
		let type = this.$planet_getType_poof$(hit);
		let sframe = this.$planet_atlas_poof$.getSpriteFrame(type);
		if(sframe){
			$planet_AudioManager_poof$.$planet_ins_poof$.$planet_playEffect_poof$(type as any);
			this.$planet_sprite_poof$.spriteFrame = sframe;
			this.node.active = true;
			Tween.stopAllByTarget(this.node);
			tween(this.node)
			.set({scale: Vec3.ZERO})
			.to(0.5, {scale: this.$planet_scale_poof$}, {easing: 'elasticOut'})
			.delay(1)
			.call(()=>np.$planet_resolve_poof$(this.node))
			.start();

		}else np.$planet_resolve_poof$(this.node);
		return np.$planet_promise_poof$;
	}

	private $planet_getType_poof$(hit: number){
		let min = Math.min(...$planet_Config_poof$.$planet_otherConfig_poof$.$planet_praise_poof$.map(t=>t.$planet_score_poof$));

		let index = hit<min ? 0 : $planet_Config_poof$.$planet_otherConfig_poof$.$planet_praise_poof$.findIndex(t=>t.$planet_score_poof$>=hit);
		index = index >= 0 ? index : $planet_Config_poof$.$planet_otherConfig_poof$.$planet_praise_poof$.length-1;
		return $planet_Config_poof$.$planet_otherConfig_poof$.$planet_praise_poof$[index].$planet_word_poof$.toLowerCase();
	}
}

